package work.sajor.wechatpush.job;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import work.sajor.wechatpush.service.Pusher;

import java.util.HashMap;
import java.util.Map;

/**
 *@ClassName JobWorker
 *@Description TODO
 *@Author ysg
 *@Date 2024/6/2 16:00
 *   这个是白天推送的消息
 *   登录微信公众号测试地址 进行获取appid key 和用户的openid
 * https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
 */
@Component
public class JobWorkerMorning {
    /**
     * 要推送的用户openid
     */
    @Value("${target.openId}")
    private String openId;

    @Autowired
    Pusher pusherService;

    @Scheduled(cron = "0 0 8 * * ?")  //每天的8点0
//    0 1,0 * * * ? *
//    @Scheduled(cron = "0 */1 * * * ?") //每一分钟推送测试
    public void goodMorning() throws InterruptedException {

        // o1CxZ6gzOmz9TCURbhRpTTe1pwgc 测试号罗琳
        // o1CxZ6pn0M7FH8byx_kRjvRxB-Qk 测试号自己的

   Map<String,String> HashCityMap=new HashMap<>();
        HashCityMap.put("o1CxZ6gmz9TCURbhRpTTe1pwgc","重庆市");
        HashCityMap.put("o1CxZ607zsr_CNeMDrBByc","苏州市");
        HashCityMap.put("o1CxZ6FH8byx_kRjvRxB-Qk","嘉兴市");
        HashCityMap.put("o1CxZ654tr7IC2OLVPhUl6s","马鞍山市");
        HashCityMap.put("o1CxZ6oqhnx8qfPyYWNLN4","重庆市");
        HashCityMap.put("o1CxZ6uDHZoycvRyol20jA","上海市");
        HashCityMap.forEach((openId1,querycity)->{{
            try {
                Thread.sleep(30000); // 休眠30秒
                pusherService.push(openId1,querycity);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }});
    }
}
